package com.dotstone.chipism.adapter;

import java.util.List;

import com.dotstone.chipism.R;
import com.dotstone.chipism.bean.LockRecord;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class LockRecordAdapter extends BaseAdapter {

	private Context context;
	private List<LockRecord> data;

	public LockRecordAdapter(Context context) {
		this.context = context;
	}

	public LockRecordAdapter(Context context, List<LockRecord> data) {
		this.data = data;
		this.context = context;
	}


	public void setData(List<LockRecord> data) {
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.item_lock_record, null);
			holdView = new HoldView();
			holdView.timeTv = (TextView) view.findViewById(R.id.time_tv);
			holdView.optionTv = (TextView)view.findViewById(R.id.option_tv);
			holdView.l = (LinearLayout)view.findViewById(R.id.l);
//			if(position%2==0){
//				view.setBackgroundColor(Color.WHITE);
//			}else{
//				view.setBackgroundColor(context.getResources().getColor(R.color.socket_bg));
//			}
			view.setTag(holdView);
		} else {
			holdView = (HoldView) view.getTag();
		}
		
		LockRecord l = data.get(position);
		if(position%2==0){
			holdView.l.setBackgroundColor(Color.WHITE);
		}else{
			holdView.l.setBackgroundColor(context.getResources().getColor(R.color.socket_bg));
		}
		holdView.timeTv.setText(l.getTime());
		holdView.optionTv.setText("开锁");
		return view;
	}

	HoldView holdView;

	class HoldView {
		private TextView timeTv,optionTv;
		private LinearLayout l;
	}


}
